#!/bin/bash
NDK=/Users/sym/Library/Android/sdk/ndk/22.0.7026061 # 这里需要替换成你本地的 NDK 路径，其他的不用修改
HOST_TAG=darwin-x86_64
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG
API=21

function build_android
{
./configure \
    --prefix=$PREFIX \
    --disable-cli \
    --enable-static \
    --enable-pic \
    --host=$my_host \
    --disable-asm \
    --cross-prefix=$CROSS_PREFIX \
    --sysroot=$NDK/toolchains/llvm/prebuilt/$HOST_TAG/sysroot \

make clean
make -j8
make install
}

#arm64-v8a
PREFIX=./android/arm64-v8a
my_host=aarch64-linux-android
export TARGET=aarch64-linux-android
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export STRINGS=$TOOLCHAIN/bin/$TARGET-strings
export AR=$TOOLCHAIN/bin/$TARGET-ar
export LD=$TOOLCHAIN/bin/$TARGET-ld
export AS=$TOOLCHAIN/bin/$TARGET-as
export STRIP=$TOOLCHAIN/bin/$TARGET-strip
export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib
export INSTALL=/usr/bin/install

CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
build_android

#armeabi-v7a
PREFIX=./android/armeabi-v7a
my_host=armv7a-linux-android
export TARGET=arm-linux-androideabi
export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang
export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++
export STRINGS=$TOOLCHAIN/bin/$TARGET-strings
export AR=$TOOLCHAIN/bin/$TARGET-ar
export LD=$TOOLCHAIN/bin/$TARGET-ld
export AS=$TOOLCHAIN/bin/$TARGET-as
export STRIP=$TOOLCHAIN/bin/$TARGET-strip
export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib
export INSTALL=/usr/bin/install

CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
build_android